package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.GreenhousefilmReturn;
import com.ruoyi.production.domain.SimpleProduction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.CartonReturn;
import com.ruoyi.production.service.ICartonReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纸箱退回Controller
 *
 * @author ruoyi
 * @date 2021-07-21
 */
@Api("纸箱退回")
@RestController
@RequestMapping("/production/cartonre")
public class CartonReturnController extends BaseController
{
    @Autowired
    private ICartonReturnService cartonReturnService;

    /**
     * 查询纸箱退回列表
     */
    @ApiOperation("查询纸箱退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:list')")
    @GetMapping("/list")
    public TableDataInfo list(CartonReturn cartonReturn)
    {
        startPage();
        List<CartonReturn> list = cartonReturnService.selectCartonReturnList(cartonReturn);
        return getDataTable(list);
    }

    /**
     * 导出纸箱退回列表
     */
    @ApiOperation("导出纸箱退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:export')")
    @Log(title = "纸箱退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CartonReturn cartonReturn)
    {
        List<CartonReturn> list = cartonReturnService.selectCartonReturnList(cartonReturn);
        ExcelUtil<CartonReturn> util = new ExcelUtil<CartonReturn>(CartonReturn.class);
        return util.exportExcel(list, "纸箱退回数据");
    }

    /**
     * 获取纸箱退回详细信息
     */
    @ApiOperation("获取纸箱退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:query')")
    @GetMapping(value = "/{cartonReturnId}")
    public AjaxResult getInfo(@PathVariable("cartonReturnId") Long cartonReturnId)
    {
        return AjaxResult.success(cartonReturnService.selectCartonReturnById(cartonReturnId));
    }

    /**
     * 新增纸箱退回
     */
    @ApiOperation("新增纸箱退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:add')")
    @Log(title = "纸箱退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CartonReturn cartonReturn)
    {
        return toAjax(cartonReturnService.insertCartonReturn(cartonReturn));
    }

    /**
     * 修改纸箱退回
     */
    @ApiOperation("修改纸箱退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:edit')")
    @Log(title = "纸箱退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CartonReturn cartonReturn)
    {
        return toAjax(cartonReturnService.updateCartonReturn(cartonReturn));
    }

    /**
     * 删除纸箱退回
     */
    @ApiOperation("删除纸箱退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:remove')")
    @Log(title = "纸箱退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartonReturnIds}")
    public AjaxResult remove(@PathVariable Long[] cartonReturnIds)
    {
        return toAjax(cartonReturnService.deleteCartonReturnByIds(cartonReturnIds));
    }

    /**
     * 获取纸箱类型下拉框
     */
    @ApiOperation("获取纸箱类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:type')")
    @GetMapping("/type")
    public TableDataInfo getType(){

        List<CartonReturn> list = cartonReturnService.getCartonType();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (CartonReturn cartonReturn:list) {
            Long id = cartonReturn.getCartonTypeId();
            String name = cartonReturn.getCartonType();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<CartonReturn> list = cartonReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (CartonReturn cartonReturn:list) {
            Long id = cartonReturn.getUserId();
            String name = cartonReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取纸箱规格下拉框
     */
    @ApiOperation("获取纸箱规格下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:specification')")
    @GetMapping("/specification/{cartonTypeId}")
    public TableDataInfo getSpecification(@PathVariable("cartonTypeId") Long cartonTypeId){

        List<String> list = cartonReturnService.getSpecification(cartonTypeId);
        return getDataTable(list);
    }

    /**
     * 获取公司下拉框
     */
    @ApiOperation("获取公司下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:cartonre:origincompany')")
    @GetMapping("/origincompany/{cartonTypeId}")
    public TableDataInfo getOriginCompany(@PathVariable("cartonTypeId") Long cartonTypeId){

        List<String> list = cartonReturnService.getOriginCompany(cartonTypeId);
        return getDataTable(list);
    }
}
